#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <string.h>

typedef enum
{
        PG_MODE_CHECK,
        PG_MODE_DISABLE,
        PG_MODE_ENABLE
} PgChecksumMode;

static PgChecksumMode mode = PG_MODE_CHECK;

static const char *progname;
char       *DataDir = NULL;
static char *only_filenode = NULL;


static void
usage(void)
{
        printf( ("%s enables, disables, or verifies data checksums in a PostgreSQL database cluster.\n\n"), progname);
        printf( ("Usage:\n"));
        printf( ("  %s [OPTION]... [DATADIR]\n"), progname);
        printf( ("\nOptions:\n"));
        printf( (" [-D, --pgdata=]DATADIR    data directory\n"));
        printf( ("  -c, --check              check data checksums (default)\n"));
        printf( ("  -d, --disable            disable data checksums\n"));
        printf( ("  -e, --enable             enable data checksums\n"));
        printf( ("  -f, --filenode=FILENODE  check only relation with specified filenode\n"));
        printf( ("  -N, --no-sync            do not wait for changes to be written safely to disk\n"));
        printf( ("  -P, --progress           show progress information\n"));
        printf( ("  -v, --verbose            output verbose messages\n"));
        printf( ("  -V, --version            output version information, then exit\n"));
        printf( ("  -?, --help               show this help, then exit\n"));
        printf( ("\nIf no data directory (DATADIR) is specified, "
                         "the environment variable PGDATA\nis used.\n\n"));
        printf( ("Report bugs to <%s>.\n"), "dh");
        printf( ("%s home page: <%s>\n"), "dh", "dh");
}



int main(int argc, char *argv[])
{
    static struct option long_options[] = {
        {"dburl", no_argument, NULL, 'u'},
        {"detail", required_argument, NULL, 'd'},
        {NULL, 0, NULL, 0}
    };
    int opt;
    int option_index = 0;
    progname = argv[0];
        int                     c;

    if (argc > 1)
        {
                if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
                {
                        usage();
                        exit(0);
                }
                if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
                {
                        puts("pg_checksums (PostgreSQL) " "dh");
                        exit(0);
                }
        }

        while ((c = getopt_long(argc, argv, "cD:deNPf:v", long_options, &option_index)) != -1)
        {
                switch (c)
                {
                        case 'c':
                                mode = PG_MODE_CHECK;
                                break;
                        case 'd':
                                mode = PG_MODE_DISABLE;
                                break;
                        case 'e':
                                mode = PG_MODE_ENABLE;
                                break;
                        case 'f':
                fprintf(stderr,"data checksums are not enabled in cluster\n");
                                break;
                        case 'N':
                fprintf(stderr," do_sync = false; data checksums are not enabled in cluster\n");
                break;
                        case 'v':
                fprintf(stderr,"verbose = true;data checksums are not enabled in cluster\n");
                                break;
                        case 'D':
                 DataDir = optarg;
                // fprintf(stderr,"DataDir = optarg; data checksums are not enabled in cluster\n");
                                break;
                        case 'P':
                fprintf(stderr,"showprogress = true; data checksums are not enabled in cluster\n");

                                break;
                        default:
                                fprintf(stderr, ("Try \"%s --help\" for more information.\n"), progname);
                                exit(1);
                }
        }
        if (DataDir == NULL)
        {
                if (optind < argc)
                        DataDir = argv[optind++];
                else
                        DataDir = getenv("PGDATA");

                /* If no DataDir was specified, and none could be found, error out */
                if (DataDir == NULL)
                {
                        fprintf(stderr, ("Try \"%s --help\" for more information.no data directory specified \n"), progname);
                        exit(1);
                }
        }

        /* Complain if any arguments remain */
        if (optind < argc)
        {
                fprintf(stderr, ("Try \"%s %s--help\" for more information.\n"),
        argv[optind],progname);
                exit(1);
        }


        if (mode == PG_MODE_CHECK)
        {
                fprintf(stderr,"data checksums are not enabled in cluster\n");
                exit(1);
        }
    return 0;
}
